const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
}

const formatDate = date => {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()

    return [year, month, day].map(formatNumber).join('/');
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const testPhone = vaule => {
    var reg = /^0?1[3|4|5|6|7|8|9][0-9]\d{8}$/;
    if (reg.test(vaule)) {
        return true;
    } else {
        return false;
    };
}

const checkEmail = vaule => {
    var reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
    if (reg.test(vaule)) {
        return true;
    } else {
        return false;
    }
}

const getDatStr = vaule => {
    switch (vaule) {
        case 1:
            return '第一天';
            break;
        case 2:
            return '第二天';
            break;
        case 3:
            return '第三天';
            break;
        case 4:
            return '第四天';
            break;
        default:
            return '';
    }
}

module.exports = {
    formatDate: formatDate,
    formatTime: formatTime,
    testPhone: testPhone,
    checkEmail: checkEmail,
    getDatStr: getDatStr
}
